/**
 * 
 */
package edu.arizona.bio5.onto.decomposition;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

import edu.arizona.bio5.onto.decomposition.persistent.PersistentAtomicDecomposition;
import edu.arizona.bio5.onto.decomposition.persistent.file.DiskADIterator;
import edu.arizona.bio5.onto.modularity.FMERunner;

/**
 *
 *
 * (c) Pavel Klinov
 *
 */
public class AllDecompositionsEvaluator {

	private static final String BIOPORTAL_AD_FOLDER = "eval/onto/bioportal-ad-top";
	private static final String BIOPORTAL_FOLDER = "eval/onto/bioportal/";
	private static final String CSV_FILE = "eval/bioportal_top_ad.csv"; 
	
	private static ADProcessingTaskRunner m_taskRunner = new ADStatsTaskRunner();
	
	
	public static void main(String[] args) throws Exception {
		
		DiskADIterator iter = new DiskADIterator(new File(BIOPORTAL_AD_FOLDER));
		File csvFile = new File(CSV_FILE);
		
		if (csvFile.exists()) {
			
			csvFile.delete();
		}
			
		csvFile.createNewFile();
		
		Writer writer = new FileWriter(csvFile);
		
		while (iter.hasNext()) {
			
			PersistentAtomicDecomposition ad  = iter.next();
			
			if (ad != null) {
				
				System.out.println("Processing... " + iter.getCurrentFolder().getName());
				
				long ts = System.currentTimeMillis();
				
				try {
					
					//m_taskRunner.setOntologyFile(new File(BIOPORTAL_FOLDER + iter.getCurrentFolder().getName()));
					writer.write(iter.getCurrentFolder().getName() + ",");
					m_taskRunner.process(ad, writer);
					
				} catch (Exception e) {
					
					writer.write("Exception: " + e.getMessage());
					writer.write("\n");
					continue;
				}
				
				ts = System.currentTimeMillis() - ts;
				
				System.out.println(" done in " + ts + " ms");

				writer.write("\n");				
				writer.flush();
			}
			else {
				System.err.println("LAD loading failed");
			}
		}
		
		writer.close();
	}
}